package Settings;

import java.awt.Color;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Observable;

/**
 * This class contains all settings of the six frame translation
 * @author Stefan Lorenz <br>
 * <b>Date:</b> 13.11.2012
 * 
 */
@SuppressWarnings("serial")
public class SixFrameSettings extends Observable implements Serializable {

    /**
     * Is six frame translation shown?
     */
    private boolean isSixFrameShown;
    /**
     * The y position of the six frame translation
     */
    private int position;
    /**
     * Array with the color of the start codons
     */
    private ArrayList<Color> startCodonColor;
    /**
     * Array with the color of the stop codons
     */
    private ArrayList<Color> stopCodonColor;
    
    /**
     * Constructor of the standard six frame translation settings
     */
    public SixFrameSettings() {
	this.isSixFrameShown = true;
	this.position = 300;
	this.startCodonColor = new ArrayList<Color>();
	this.stopCodonColor = new ArrayList<Color>();

	this.startCodonColor.add(Color.GREEN);
	this.startCodonColor.add(Color.RED);
	for (int i = 0; i < 6; i++)
	    this.stopCodonColor.add(Color.LIGHT_GRAY);
    }

    /**
     * Sets the start and stop codons
     * @param startcodons list with start codons
     * @param stopcodons list with stop codons
     */
    public void setStartStop(ArrayList<String> startcodons, ArrayList<String> stopcodons) {
	//start codons
	//keep colors and add new ones if necessary
	if(startcodons.size()*2 > this.startCodonColor.size()){
	    for (int i = startcodons.size(); i < (startcodons.size() * 2); i++) {
		    this.startCodonColor.add(Color.RED);
	    }
	}
	//remove colors
	else if(startcodons.size()*2 < this.startCodonColor.size()){
	    for (int i = startcodons.size(); i < (startcodons.size() * 2); i++) {
		    this.startCodonColor.remove(this.startCodonColor.size()-1);
	    }
	}
	//stop codons
	//keep colors and add new ones if necessary
	if(stopcodons.size()*2 > this.stopCodonColor.size()){
	    for (int i = stopcodons.size(); i < (stopcodons.size() * 2); i++) {
		    this.stopCodonColor.add(Color.LIGHT_GRAY);
	    }
	}
	//remove colors
	else if(stopcodons.size()*2 < this.stopCodonColor.size()){
	    for (int i = stopcodons.size(); i < (stopcodons.size() * 2); i++) {
		    this.stopCodonColor.remove(this.stopCodonColor.size()-1);
	    }
	}
    }

    /**
     * Returns {@link Boolean} if six frame tanslation is shown or not
     * @return is six frame translation shown?
     */
    public boolean isSixFrameShown() {
	return isSixFrameShown;
    }

    /**
     * Sets the six frame translation visible or invisible
     * @param isSixFrameShown 
     */
    public void setSixFrameShown(boolean isSixFrameShown) {
	this.isSixFrameShown = isSixFrameShown;
	setChanged();
    }

    /**
     * Sets the y position of the six frame translation
     * @param position position of the six frame translation
     */
    public void setPosition(int position) {
	this.position = position;
	setChanged();
    }

    /**
     * Returns the y position of the six frame translation
     * @return the position of the six frame translation
     */
    public int getPosition() {
	return position;
    }

    /* (non-Javadoc)
     * @see java.util.Observable#setChanged()
     */
    @Override
    protected synchronized void setChanged() {
	super.setChanged();
	notifyObservers();
    }

    /**
     * Sets the stop codons
     * @param stopCodonColor list with stop codons
     */
    public void setStopCodonColor(ArrayList<Color> stopCodonColor) {
	this.stopCodonColor = stopCodonColor;
    }

    /**
     * Returns a list with stop codons
     * @return a list with stop codons
     */
    public ArrayList<Color> getStopCodonColor() {
	return stopCodonColor;
    }

    /**
     * Sets a list with start codons
     * @param startCodonColor a list with start codons
     */
    public void setStartCodonColor(ArrayList<Color> startCodonColor) {
	this.startCodonColor = startCodonColor;
    }

    /**
     * Returns a list with the start codons
     * @return a list with start codons
     */
    public ArrayList<Color> getStartCodonColor() {
	return startCodonColor;
    }
}
